#!/usr/bin/python

if __name__ == "__main__":
    from optparse import OptionParser
    from pgdump_rsync.xmlrpc_transport import XMLRPCServerProxy
    from pgdump_rsync.client import Config, sync_dumps

    parser = OptionParser(usage="usage: \n  %prog <server-uri> <last-file> <new-file>")

    parser.add_option("-p", "--protocol", action="store", type="string",
                      dest="protocol", default="xmlrpc",
                      help="Transport protocol to use. Only xmlrpc available")
    parser.add_option("", "--min-rsync-size", action="store", type="int",
                      dest="min_rsync_size", default=2**16,
                      help="Minimum table size for using rsync")
    parser.add_option("", "--blobs-ignore-hash", action="store_true",
                      dest="blobs_ignore_hash", default=False,
                      help="Don't calculate hash on blobs, if size doesn't match, just sync")

    XMLRPCServerProxy.add_parse_opts(parser)

    (opts, args) = parser.parse_args()

    if len(args) != 3:
        parser.error("Error, not enought arguments")

    server_uri, last_file, new_file = args
    if opts.protocol == "xmlrpc":
        server = XMLRPCServerProxy(server_uri, opts)
    config = Config(opts.min_rsync_size, opts.blobs_ignore_hash)
    sync_dumps(last_file, server, new_file, config)
